<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset = UTF-8" />
        <link href="public/css.css" rel="stylesheet" type="text/css" />
        <title>Facebook</title>
    </head>

    <body>
        <div class="chung">
            <?php
            require_once './model/works.php';
            $keyword = new Works();
            $keyword->table_name = "works";
            ?>
            <?php
            if (!isset($_GET["page"]))
                $page = 1;
            else
                $page = $_GET["page"];

            $total = $keyword->countWords();
            ?>
            <div class="hinh"></div>
            <h2>Facebook</h2>
            <div class="menu">
                <ul>
                    <li><a rel="home" href="http://facebook.com/" title="Nghe Nhạc" class="logo">Facebook</a></li>
                    <li><a rel="home" href="http://haivl.com/" title="Nghe Nhạc" class="logo">Hài vl</a></li>
                    <li><a rel="home" href="http://forum.vietdesigner.net/" title="Nghe Nhạc" class="logo">VietDesigner</a></li>
                    <li><a rel="home" href="http://www.nhaccuatui.com/" title="Nghe Nhạc" class="logo">Music</a></li>
                    <li> <input type="text" id="type"/><input type="button" value="Search" id="ty"></li>
                </ul>
                <div class="thanh"></div>

            </div>

            <div class="noidung">
                <hr id="like"></hr>

                <div class="nav" style="clear: both;"> 
                    <ul>
                        <?php if (!isset($_GET["page"])):
                            ?>

                            <a href="index.php?page=<?php echo $_GET['page'] = 1 ?>">
                            </a>
                        <?php endif; ?>


                        <li> <a href="index.php?page=1">Fist</a></li>
                        <li><a href="index.php?page=<?php echo $_GET["page"] - 1 ?>"><<</a></li>

                        <?php for ($i = 1; $i <= 7; $i++): ?>
                            <?php if (($_GET["page"] == 1) || ($_GET["page"] == 2) || ($_GET["page"] == 3) || ($_GET["page"] == 4)): ?>            
                                <?php for ($i = 1; $i <= 7; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php elseif (($_GET["page"] == $total / PAGE) || ($_GET["page"] == $total / PAGE - 1) || ($_GET["page"] == $total / PAGE - 2) || ($_GET["page"] == $total / PAGE - 3)): ?>        
                                <?php for ($i = $total / PAGE - 7; $i <= $total / PAGE; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php else : ?>
                                <?php for ($i = $_GET["page"] - 3; $i <= $_GET["page"] + 3; $i++): ?>
                                    <li><a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a></li>
                                    <?php if ($_GET["page"] == $i): ?>
                                        <?php $keyword->begin; ?>
                                        <?php $keyword->theend = PAGE; ?>
                                    <?php endif; ?>
                                <?php endfor; ?>
                            <?php endif; ?> 
                        <?php endfor; ?>
                        <li><a href="index.php?page=<?php echo $_GET['page'] + 1 ?>"> >></a></li>           
                        <li><a href="index.php?page=<?php echo $total / PAGE ?>">Last</a></li>

                        <?php $keywords = $keyword->select($page); ?>
                    </ul>
                </div>

                <table border="1px" style="clear: both;" class="nd">
                    <tr  id="tr" >
                        <td>Id</td>
                        <td>Name</td>
                        <td>Description</td>
                        <td>Oparetion</td>
                        <td>Images</td>
                    </tr>
                    <?php foreach ($keywords as $keywordss): ?>
                        <tr class="b">
                            <td><?php echo $keywordss['id']; ?></td>
                            <td><?php echo $keywordss['name']; ?></td>
                            <td><?php echo substr($keywordss['description'], 0, 100); ?></td>
                            <td><img src="public/images/edit.png" width="15px" height="15px"><a href="up.php">Edit</a>
                                <img src="public/images/view.png" width="15px" height="15px"><a href="up.php">View</a><br>
                                <img src="public/images/delete.png" width="15px" height="15px"><a href="up.php">Delete</a></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            </div>
            <div class="cuoi">Nguyên C12TDT</div>

        </div>
    </body>
</html>